- frmUpdateCustomerDetails.cs
- project /
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 namespace WarehouseManagementSystem
11 {
12 public partial class frmUpdateCustomerDetails : Form
13 {
14 SqlDataReader rdr= null;
15 DataTable dtable = new DataTable();
16 SqlConnection con = null;
17 SqlCommand cmd = null;
18 DataTable dt = new DataTable();
19 ConnectionString cs = new ConnectionString();
20 public frmUpdateCustomerDetails()
21 {
22 InitializeComponent();
23 }
24
25
26
27 private void Email_Address_Validating(object sender, CancelEventArgs e)
28 {
29 System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
30 if (txtEmail_Address.Text.Length > 0)
31 {
32 if (!rEMail.IsMatch(txtEmail_Address.Text))
33 {
34 MessageBox.Show("invalid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
35 txtEmail_Address.SelectAll();
36 e.Cancel = true;
37 }
38 }
39 }
40
41 private void Name_Of_User_KeyPress(object sender, KeyPressEventArgs e)
42 {
43 e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Space);
44 }
45
46 private void Username_Validating(object sender, CancelEventArgs e)
47 {
48 System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9_]");
49 if (txtUsername.Text.Length > 0)
50 {
51 if (!rEMail.IsMatch(txtUsername.Text))
52 {
53 MessageBox.Show("only letters,numbers and underscore is allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
54 txtUsername.SelectAll();
55 e.Cancel = true;
56 }
57 }
58 }
59
60
61 private void Update_record_Click(object sender, EventArgs e)
62 {
63 if (txtUsername.Text == "")
64 {
65 MessageBox.Show("Please enter username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
66 txtUsername.Focus();
67 return;
68 }
69
70 if (txtPassword.Text == "")
71 {
72 MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
73 txtPassword.Focus();
74 return;
75 }
76 if (txtName.Text == "")
77 {
78 MessageBox.Show("Please enter name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
79 txtName.Focus();
80 return;
81 }
82 if (txtContact_no.Text == "")
83 {
84 MessageBox.Show("Please enter contact no.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
85 txtContact_no.Focus();
86 return;
87 }
88 if (txtEmail_Address.Text == "")
89 {
90 MessageBox.Show("Please enter email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
91 txtEmail_Address.Focus();
92 return;
93 }
94 try
95 {
96 con = new SqlConnection(cs.DBConn);
97 con.Open();
98
99 string cb = "update registration set password='" + txtPassword.Text + "',contactno='" + txtContact_no.Text + "',email='" + txtEmail_Address.Text + "',name='" + txtName.Text + "' where username='" + txtUsername.Text + "'";
100 cmd = new SqlCommand(cb);
101 cmd.Connection = con;
102 cmd.ExecuteReader();
103 con.Close();
104
105 MessageBox.Show("Successfully updated", "User Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
106 btnUpdate_record.Enabled = false;
107 }
108 catch (Exception ex)
109 {
110 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
111 }
112 }
113
114
115 private void txtContact_no_KeyPress(object sender, KeyPressEventArgs e)
116 {
117 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
118 {
119 e.Handled = false;
120 }
121 else
122 {
123 e.Handled = true;
124 }
125 }
126 public void Getdata()
127 {
128 con = new SqlConnection(cs.DBConn);
129 con.Open();
130 cmd = con.CreateCommand();
131
132 cmd.CommandText = "SELECT username,password,name,contactno,email FROM registration WHERE username = '" + textBox1.Text.Trim() + "'";
133 rdr = cmd.ExecuteReader();
134
135 if (rdr.Read())
136 {
137 txtUsername.Text = (rdr.GetString(0).Trim());
138 txtPassword.Text = (rdr.GetString(1).Trim());
139 txtName.Text = (rdr.GetString(2).Trim());
140 txtContact_no.Text = (rdr.GetString(3).Trim());
141 txtEmail_Address.Text = (rdr.GetString(4).Trim());
142 }
143
144 if ((rdr != null))
145 {
146 rdr.Close();
147 }
148 if (con.State == ConnectionState.Open)
149 {
150 con.Close();
151 }
152 }
153 private void frmUpdateCustomerDetails_Load(object sender, EventArgs e)
154 {
155 txtUsername.ReadOnly = true;
156 Getdata();
157 }
158
159
160 }
161
162
163 }